<template>
  <div class="page-article" v-if="model">
    <div class="d-flex py-3 px-2 border-bottom">
      <div @click="this.$router.go(-1)" class="iconfont icon-fenxiang text-blue"></div>
      <strong class="flex-1 text-blue text-ellipsis pl-2 pr-2">{{
        model.title
      }}</strong>
      <div class="text-grey fs-xs">2022-05-08</div>
    </div>
    <div v-html="model.body" class="px-3 body fs-lg"></div>
    <div class="px-3 border-top py-3">
      <div class="d-flex ai-center">
        <i class="iconfont icon-fenxiang text-blue"></i>
        <strong class="text-blue fs-lg ml-1">相关资讯</strong>
      </div>
      <div class="pt-2 fs-lg">
        <router-link
          class="py-1 text-ellipsis"
          tag="div"
          :to="`/articles/${item._id}`"
          v-for="item in model.related"
          :key="item"
          >{{ item.title }}</router-link
        ><br />
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onBeforeMount, watch } from "vue";
import { getActicle } from "@/api";
export default {
  props: {
    id: {
      required: true,
    },
  },
  setup(props) {
    const model = ref();
    const fetch = async () => {
      const { data: res } = await getActicle(props.id);
      model.value = res;
    };
    watch(
      () => props.id,
      () => {
        fetch();
      }
    );
    onBeforeMount(() => {
      fetch();
    });
    return { model };
  },
};
</script>

<style lang="scss">
.page-article {
  .body {
    img {
      max-width: 100%;
      height: auto;
    }
    iframe {
      width: 100%;
      height: auto;
    }
  }
}
</style>
